package com.stox.ui.javafx.charting.widget.axis;

import java.util.List;

import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.stox.ui.javafx.charting.model.plot.AbstractPrimaryPlot;
import com.stox.ui.javafx.charting.model.uiunit.AbstractPrimaryUiUnit;

@Component
@SuppressWarnings("rawtypes")
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class InformationAxis extends AbstractHorizontalAxis {
	
	private AbstractPrimaryUiUnit uiUnit;
	
	public void setUiUnit(AbstractPrimaryUiUnit uiUnit) {
		this.uiUnit = uiUnit;
	}
	
	@SuppressWarnings("unchecked")
	public void paint() {
		super.paint();
		AbstractPrimaryPlot plot = getChart().getChartingView().getPrimaryChart().getFrontPlot();
		if(null == plot || null == plot.getUiUnits() || plot.getUiUnits().isEmpty()) return;
		if(null == uiUnit || !plot.equals(uiUnit.getPlot())) {
			uiUnit = (AbstractPrimaryUiUnit)plot.getUiUnits().get(0);
		}
			
		if(null == uiUnit) return;
		List<String> info = uiUnit.info();
		double labelWidth = getWidth()/info.size();
		for(int i = 0; i < info.size(); i++) {
			gc.strokeText(info.get(i), i*labelWidth + labelWidth/2, getHeight()/2);
		}
		
	}

}
